package com.neu.flashmall.product.controller;

import com.github.pagehelper.PageInfo;
import com.neu.common.utils.Result;
import com.neu.flashmall.product.entity.PmsBrand;
import com.neu.flashmall.product.entity.PmsSpuInfo;
import com.neu.flashmall.product.feign.MSFeignService;
import com.neu.flashmall.product.service.PmsBrandService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author:Tang
 *
 */
@RestController
@RequestMapping("/pms_brand")
@Api(value = "商品品牌管理接口")
public class PmsBrandController {
    @Resource
    private PmsBrandService pmsBrandService;

    @Resource
    private MSFeignService authorityFeignService;

    @PostMapping("checkBrandName")
    @ApiOperation("查看品牌名称是否相同")
    public Result checkBrandName(@RequestBody String name){
        return Result.ok().put(pmsBrandService.checkBrandName(name));
    }

    @GetMapping("getAllBrands")
    @ApiOperation(value = "获取所有品牌信息")
    public Result getAllBrands(){
        List<PmsBrand> pmsBrands = pmsBrandService.selectAll();
        return Result.ok().put(pmsBrands);
    }

    @GetMapping("getPaged")
    @ApiOperation(value = "获取所有品牌分页信息")
    public Result getPaged(
            @RequestParam(defaultValue = "1") int pageNum,
            @RequestParam(defaultValue = "3") int pageSize){
        PageInfo<PmsBrand> pageInfo = pmsBrandService.getPaged(pageNum,pageSize);
        return Result.ok().put(pageInfo);
    }

    @PostMapping("/check/insert")
    @ApiOperation("添加商品品牌信息")
    public Result insert(@RequestBody PmsBrand pmsBrand){
        Long lastId = pmsBrandService.insert(pmsBrand);
        if(lastId > 0){
            return Result.ok().put(lastId);
        }
        return Result.error();
    }

    @PostMapping("/check/update")
    @ApiOperation("更新商品品牌信息")
    public  Result update(@RequestBody PmsBrand pmsBrand){
        if(pmsBrandService.update(pmsBrand)>0){
            return Result.ok().put(true);
        }
        return Result.error();
    }

    @DeleteMapping("/check/deleteBrand")
    @ApiOperation("删除商品品牌信息")
    public Result delete( Long id){
        if(pmsBrandService.delete(id)>0){
            return Result.ok().put(true);
        }
        return Result.error();
    }

    @PostMapping("/check/updateLogo")
    @ApiOperation("更新商品品牌信息")
    public  Result updateLogo(@RequestBody PmsBrand pmsBrand){
        if(pmsBrandService.updateLogo(pmsBrand) > 0){
            return Result.ok().put(true);
        }
        return Result.error();
    }

    @GetMapping("/check/setHot")
    @ApiOperation("更新商品品牌信息")
    public  Result setHot(Long id,int hot){
        String result = this.pmsBrandService.setHot(id,hot);
        if("success".equals(result)){
            return Result.ok().setMessage(result);
        }
        return Result.error();
    }

    @GetMapping("/getHot")
    @ApiOperation("更新商品品牌信息")
    public  Result getHot(){
        return Result.ok().put(this.pmsBrandService.getHot());
    }

    @GetMapping("/getBrandById")
    public Result getBrandById(Long id){
        PmsBrand result = pmsBrandService.getOneById(id);
        return Result.ok().put(result);
    }
}
